const jwt = require('jsonwebtoken');
const {secret} = require('../../config/config');
module.exports =  (req,res,next)=>{
 //获取token
 let token = req.get('token');
 if (!token) {
   return res.json({
     code: '3000',
     msg: 'token 还未传递',
     data: null
   })
 }

   //校验token
   jwt.verify(token, secret, (err, data) => {
    if (err) {
      return res.json({
        code: '3001',
        msg: 'token 失败',
        data: null
      });
    }
    //保存用户信息
    req.user =data;
    next();
  })
};